package com.gator.rabbitmq.pablo_rabbitmq.simple;


import com.gator.rabbitmq.pablo_rabbitmq.utils.ConnectionUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;

/**
 * @Author PABLO
 * @Date 2022/6/4 21:56
 * @Desc 消费者
 */
public class SimpleQueueConsumer {

    public static final String QUEUE_NAME = "hello";

    public static void main(String[] args) {
        Channel channel = ConnectionUtils.getConnectionAndChannel();

        try {
            //消费
            DeliverCallback deliverCallback = (consumerTag, message) -> {
                System.out.println(new String(message.getBody()));
            };
            //消费者取消消费
            CancelCallback cancelCallback = consumerTag -> {
                System.out.println("msg被中断...");
            };
            //消费
            channel.basicConsume(QUEUE_NAME, true, deliverCallback,cancelCallback);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
